/**
 * 项目管理管理初始化
 */

var riskProData;
var dalayTasksData;
var allTasksByGroupData;
var allTaskFinishedByGroupData;
var allTaskUnFinishedByGroupData;
var lastWeekByGroupData;
var lastWeekFinishedByGroupData;
var lastWeekUnFinishedByGroupData;
var thisWeekByGroupData;
var thisWeekFinishedByGroupData;
var thisWeekUnFinishedByGroupData;
var nextWeekByGroupData;
var nextWeekFinishedByGroupData;
var nextWeekUnFinishedByGroupData;
var lastWeekPlanedByGroupData;
var lastWeekUnPlanedByGroupData;
var thisWeekPlanedByGroupData;
var thisWeekUnPlanedByGroupData;
var dalayTasksByGroupData;
var dealedBata;
var thisWeekNewData;
var thisWeekData
var left1Data;
var left2Data;
var left3Data;
var workloadData;
var questionColumns = [];
$(function() {
	$
			.post(
					"/problems/overall",
					function(data, status) {
						var rusult = "本周处理：<a href='javascript:openProblems(\"dealed\");'>"
								+ data.dealed.length + "</a>个。 ";
						rusult += "本周新增：<a href='javascript:openProblems(\"thisWeekNew\");'>"
								+ data.thisWeekNew.length + "</a>个。";
						rusult += "本周剩余：<a href='javascript:openProblems(\"thisWeek\");'>"
								+ data.thisWeek.length
								+ "</a>个。  <button type=\"button\" class=\"btn btn-primary \" onclick=\"exportExcel()\" id=\"\"> <i class=\"fa fa-excel\"></i>&nbsp;导出Excel</button><br/>";

						dealedBata = data.dealed;
						thisWeekNewData = data.thisWeekNew;
						thisWeekData = data.thisWeek;

						if (data.group["1101_电子税务局_局端系统_电子报税"] != undefined) {
							rusult += "1101_电子税务局_局端系统_电子报税"
									+ "还剩：<a href='javascript:openProblems(\"left1\")'>"
									+ data.group["1101_电子税务局_局端系统_电子报税"].length
									+ "</a>个。<br/>";
							left1Data = data.group["1101_电子税务局_局端系统_电子报税"];
						}
						if (data.group["1102_电子税务局_局端系统_在线办税"] != undefined) {
							rusult += "1102_电子税务局_局端系统_在线办税"
									+ "还剩：<a href='javascript:openProblems(\"left2\")'>"
									+ data.group["1102_电子税务局_局端系统_在线办税"].length
									+ "</a>个。<br/>";
							left2Data = data.group["1102_电子税务局_局端系统_在线办税"];
						}
						if (data.group["1103_电子税务局_局端系统_信息服务"] != undefined) {
							rusult += "1103_电子税务局_局端系统_信息服务"
									+ "还剩：<a href='javascript:openProblems(\"left3\")'>"
									+ data.group["1103_电子税务局_局端系统_信息服务"].length
									+ "</a>个。<br/>";
							left3Data = data.group["1103_电子税务局_局端系统_信息服务"];
						}
						$("#total").html(rusult);
					});

	$
			.post(
					"/plan/topdesk",
					function(data, status) {

						allTasksByGroupData = data.allTasksByGroup;
						allTaskFinishedByGroupData = data.allTaskFinishedByGroup;
						allTaskUnFinishedByGroupData = data.allTaskUnFinishedByGroup;
						lastWeekByGroupData = data.lastWeekByGroup;
						lastWeekFinishedByGroupData = data.lastWeekFinishedByGroup;
						lastWeekUnFinishedByGroupData = data.lastWeekUnFinishedByGroup;
						thisWeekByGroupData = data.thisWeekByGroup;
						thisWeekFinishedByGroupData = data.thisWeekFinishedByGroup;
						thisWeekUnFinishedByGroupData = data.thisWeekUnFinishedByGroup;
						nextWeekByGroupData = data.nextWeekByGroup;
						nextWeekFinishedByGroupData = data.nextWeekFinishedByGroup;
						nextWeekUnFinishedByGroupData = data.nextWeekUnFinishedByGroup;
						dalayTasksByGroupData = data.dalayTasksByGroup;
						lastWeekPlanedByGroupData = data.lastWeekPlanedByGroup;
						lastWeekUnPlanedByGroupData = data.lastWeekUnPlanedByGroup;
						thisWeekPlanedByGroupData = data.thisWeekPlanedByGroup;
						thisWeekUnPlanedByGroupData = data.thisWeekUnPlanedByGroup;

						var result = "任务共计<a href='javascript:openTasks(\"allTask\");'>"
								+ data.allTasks.length
								+ "</a>个,完成<a href='javascript:openTasks(\"allTaskFinished\");'>"
								+ data.allTaskFinished.length
								+ "</a>个,未完成<a href='javascript:openTasks(\"allTaskUnFinished\");'>"
								+ data.allTaskUnFinished.length
								+ "</a>个,完成率为"
								+ (data.allTaskFinished.length
										/ data.allTasks.length * 100)
										.toFixed(0) + "%<br/>";
						result += "上周("
								+ data.lastWeekMonday.substring(0, 10)
								+ "至"
								+ data.lastWeekSunday.substring(0, 10)
								+ ")计划完成<a href='javascript:openTasks(\"lastWeek\");'>"
								+ data.lastWeek.length
								+ "</a>个,实际完成<a href='javascript:openTasks(\"lastWeekFinished\");'>"
								+ data.lastWeekFinished.length
								+ "</a>个,未完成<a href='javascript:openTasks(\"lastWeekUnFinished\");'>"
								+ data.lastWeekUnFinished.length
								+ "</a>个,完成率为"
								+ (data.lastWeekFinished.length
										/ data.lastWeek.length * 100)
										.toFixed(0) + "%<br/>";

						result += "<span style='white-space:pre;'>                                                    计划内任务<a href='javascript:openTasks(\"lastWeekPlaned\");'>"
								+ data.lastWeekPlaned.length
								+ "</a>个,</span>"
								+ "临时性计划任务<a href='javascript:openTasks(\"lastWeekUnPlaned\");'>"
								+ data.lastWeekUnPlaned.length
								+ "</a>个,"
								+ "计划率为"
								+ (data.lastWeekPlaned.length
										/ data.lastWeek.length * 100)
										.toFixed(0) + "%<br/>";

						result += "本周("
								+ data.thisWeekMonday.substring(0, 10)
								+ "至"
								+ data.thisWeekSunday.substring(0, 10)
								+ ")计划完成<a href='javascript:openTasks(\"thisWeek\");'>"
								+ data.thisWeek.length
								+ "</a>个,实际完成<a href='javascript:openTasks(\"thisWeekFinished\");'>"
								+ data.thisWeekFinished.length
								+ "</a>个,未完成<a href='javascript:openTasks(\"thisWeekUnFinished\");'>"
								+ data.thisWeekUnFinished.length
								+ "</a>个,完成率为"
								+ (data.thisWeekFinished.length
										/ data.thisWeek.length * 100)
										.toFixed(0) + "%<br/>";

						result += "<span style='white-space:pre;'>                                                    计划内任务<a href='javascript:openTasks(\"thisWeekPlaned\");'>"
								+ data.thisWeekPlaned.length
								+ "</a>个,</span>"
								+ "临时性计划任务<a href='javascript:openTasks(\"thisWeekUnPlaned\");'>"
								+ data.thisWeekUnPlaned.length
								+ "</a>个,"
								+ "计划率为"
								+ (data.thisWeekPlaned.length
										/ data.thisWeek.length * 100)
										.toFixed(0) + "%<br/>";

						result += "下周("
								+ data.nextWeekMonday.substring(0, 10)
								+ "至"
								+ data.nextWeekSunday.substring(0, 10)
								+ ")计划完成<a href='javascript:openTasks(\"nextWeek\");'>"
								+ data.nextWeek.length
								+ "</a>个,实际完成<a href='javascript:openTasks(\"nextWeekFinished\");'>"
								+ data.nextWeekFinished.length
								+ "</a>个,未完成<a href='javascript:openTasks(\"nextWeekUnFinished\");'>"
								+ data.nextWeekUnFinished.length
								+ "</a>个完成率为"
								+ (data.nextWeekFinished.length
										/ data.nextWeek.length * 100)
										.toFixed(0) + "%<br/>";

						dalayTasksData = data.dalayTasks;
						var risk2 = "延期任务：<a href='javascript:openTasks(\"DalayTasks\");'>"
								+ dalayTasksData.length + "</a>个<br/>";

						$("#risk2").html(risk2);
						$("#plan").html(result);

					});

	$
			.post(
					"/servicesList/desktop",
					function(data, status) {
						// 0暂不发布，1已发布，2已作废，3新增待发布，4已修改待发布，5已作废待发布，6过时
						var result = "局端提供接口共计<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=\", \"局端对外提供接口\");'>"
								+ data.list.length
								+ "</a>个,已发布<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=1\", \"已发布\");'>"
								+ (data.zt1 == null ? 0 : data.zt1.length)
								+ "</a>个,新增待发布<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=3\", \"新增待发布\");'>"
								+ (data.zt3 == null ? 0 : data.zt3.length)
								+ "</a>个,已修改待发布<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=4\", \"已修改待发布\");'>"
								+ (data.zt4 == null ? 0 : data.zt4.length)
								+ "</a>个,已作废待发布<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=0\", \"已作废待发布\");'>"
								+ (data.zt0 == null ? 0 : data.zt0.length)
								+ "</a>个,暂不发布<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=2\", \"暂不发布\");'>"
								+ (data.zt2 == null ? 0 : data.zt2.length)
								+ "</a>个,已作废<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=5\", \"已作废\");'>"
								+ (data.zt5 == null ? 0 : data.zt5.length)
								+ "</a>个,过时<a href='javascript:openTab(\"/servicesList/getList?path=/servicesList/list&type=6\", \"过时\");'>"
								+ (data.zt6 == null ? 0 : data.zt6.length)
								+ "</a>个";
						$("#servicesList").html(result);

					});
	$
			.post(
					"/versionPlan/topdesk",
					function(data, status) {
						var result = "当前版本号：<a href='javascript:openTab(\"/versionPlan/getList?version="
								+ data.nowVersion
								+ "\", \"版本信息\");'>"
								+ data.nowVersion
								+ " </a> 当前版本需要发布"
								+ data.plans.length + "个用例<br/>";
						$("#versionPlan").html(result);

						var versionNums = data.versions;
						$("#versionPlanPage").select2({
							data : versionNums,
							width : "200"
						})
						$("#versionPlanPage").val(data.nowVersion).trigger(
								'change')
					});

	$
			.post(
					"/risk/planRisk",
					function(data, status) {
						riskProData = data.riskPro;
						var result = "问题风险:未安排计划的问题管理平台数据共计<a href='javascript:openProblems(\"riskPro\");'>"
								+ riskProData.length + "</a>个";
						$("#risk1").html(result);

						// 拼接人员工作量列表
						workloadData = data.workLoad;
						var mdata = data.colDate;
						var t0 = {
							field : "name",
							title : "姓名\日期",
							align : "center",
							valign : 'middle'
						};

						var num = mdata.length + 1;
						questionColumns.push(t0);
						for (var i = 0; i < mdata.length; i++) {
							if (i >= 7 && i <= 13) {
								var temp = {
									field : "wl" + (i + 1),
									title : mdata[i],
									align : "center",
									valign : 'middle',
									cellStyle : function(value, row, index) {
										var bg_color = '#00ff00';
										return {
											css : {
												"background-color" : bg_color
											}
										}
									}
								};// 手动拼接columns
								questionColumns.push(temp);
							} else {
								var temp = {
									field : "wl" + (i + 1),
									title : mdata[i],
									align : "center",
									valign : 'middle'
								};// 手动拼接columns
								questionColumns.push(temp);
							}

						}
						$('#workload').bootstrapTable({
							columns : questionColumns,
							data : workloadData,
							pageSize : 20,
							pagination : true,
							striped : true,
							pageNumber : 1,
							sidePagination : 'client',
							// showColumns : true,
							clickToSelect : true,
							pagination : true
						});

					});
	$
			.post(
					"/risk/versionPlanRisk",
					function(data, status) {
						var risk3 = "无版本计划风险：应该安排版本计划且未安排的任务共有<a href='javascript:openVersionPlanRisk(\"noVersionPlan\");'>"
								+ data.noVersionPlan.length + "</a>个";
						var risk4 = "延期版本计划风险：延期且未出厂的任务共有<a href='javascript:openVersionPlanRisk(\"delayVersionPlan\");'>"
								+ data.delayVersionPlan.length + "</a>个";
						$("#risk3").html(risk3);
						$("#risk4").html(risk4);
					});
	$("#problemFile").fileinput({
		language : 'zh', // 设置语言
		uploadUrl : "/problems/uploadFile", // 上传的地址
		allowedFileExtensions : [ 'xlsx' ],// 接收的文件后缀
		uploadAsync : true, // 默认异步上传
		showUpload : true, // 是否显示上传按钮
		showRemove : true, // 显示移除按钮
		showPreview : false, // 是否显示预览
		showCaption : true,// 是否显示标题
		browseClass : "btn btn-primary", // 按钮样式
		dropZoneEnabled : false,// 是否显示拖拽区域
		maxFileCount : 1, // 表示允许同时上传的最大文件个数
		enctype : 'multipart/form-data',
		validateInitialCount : true
	});

	$("#planFile").fileinput({
		language : 'zh', // 设置语言
		uploadUrl : "/plan/uploadFile", // 上传的地址
		allowedFileExtensions : [ 'mpp' ],// 接收的文件后缀
		uploadAsync : true, // 默认异步上传
		showUpload : true, // 是否显示上传按钮
		showRemove : true, // 显示移除按钮
		showPreview : false, // 是否显示预览
		showCaption : true,// 是否显示标题
		browseClass : "btn btn-primary", // 按钮样式
		dropZoneEnabled : false,// 是否显示拖拽区域
		maxFileCount : 1, // 表示允许同时上传的最大文件个数
		enctype : 'multipart/form-data',
		validateInitialCount : true
	});

});
function openProblems(type) {
	var tempPro;
	var title;
	if (type == "riskPro") {
		title = "问题风险:未安排计划的问题管理平台数据";
		tempPro = riskProData;
	} else if (type == "dealed") {
		title = "本周处理问题";
		tempPro = dealedBata;
	} else if (type == "thisWeekNew") {
		title = "本周新增问题";
		tempPro = thisWeekNewData;
	} else if (type == "thisWeek") {
		title = "本周剩余问题";
		tempPro = thisWeekData;
	} else if (type == "left1") {
		title = "电子报税本周剩余问题";
		tempPro = left1Data;
	} else if (type == "left2") {
		title = "电子办税本周剩余问题";
		tempPro = left2Data;
	} else if (type == "left3") {
		title = "信息服务本周剩余问题";
		tempPro = left3Data;
	}

	layer.open({
		type : 2,
		title : title,
		shadeClose : true,
		shade : false,
		maxmin : true, // 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : '/problems/problemsPage',
		success : function(layero, index) {
			var iframeWin = window[layero.find('iframe')[0]['name']];
			var flag = iframeWin.setTable(tempPro);
		}
	});
}
function openTasks(type) {
	var tempTask;
	var title;
	if (type == "DalayTasks") {
		tempTask = dalayTasksByGroupData;
		title = "问题风险:延期任务";
	} else if (type == "allTask") {
		tempTask = allTasksByGroupData;
		title = "所有任务";
	} else if (type == "allTaskFinished") {
		tempTask = allTaskFinishedByGroupData;
		title = "所有完成任务";
	} else if (type == "allTaskUnFinished") {
		tempTask = allTaskUnFinishedByGroupData;
		title = "所有未任务";
	} else if (type == "lastWeek") {
		tempTask = lastWeekByGroupData;
		title = "上周任务";
	} else if (type == "lastWeekFinished") {
		tempTask = lastWeekFinishedByGroupData;
		title = "上周完成任务";
	} else if (type == "lastWeekUnFinished") {
		title = "上周未完成任务";
		tempTask = lastWeekUnFinishedByGroupData;
	} else if (type == "thisWeek") {
		title = "本周任务";
		tempTask = thisWeekByGroupData;
	} else if (type == "thisWeekFinished") {
		title = "本周完成任务";
		tempTask = thisWeekFinishedByGroupData;
	} else if (type == "thisWeekUnFinished") {
		title = "本周未完成任务";
		tempTask = thisWeekUnFinishedByGroupData;
	} else if (type == "nextWeek") {
		title = "下周任务";
		tempTask = nextWeekByGroupData;
	} else if (type == "nextWeekFinished") {
		title = "下周完成任务";
		tempTask = nextWeekFinishedByGroupData;
	} else if (type == "nextWeekUnFinished") {
		title = "下周未完成任务";
		tempTask = nextWeekUnFinishedByGroupData;
	} else if (type == "lastWeekPlaned") {
		title = "上周计划内任务";
		tempTask = lastWeekPlanedByGroupData;
	} else if (type == "lastWeekUnPlaned") {
		title = "上周临时性任务";
		tempTask = lastWeekUnPlanedByGroupData;
	} else if (type == "thisWeekPlaned") {
		title = "本周计划内任务";
		tempTask = thisWeekPlanedByGroupData;
	} else if (type == "thisWeekUnPlaned") {
		title = "本周临时性任务";
		tempTask = thisWeekUnPlanedByGroupData;
	} else {
		tempTask = null;
	}

	if (tempTask != null) {
		layer.open({
			type : 2,
			title : title,
			shadeClose : true,
			shade : false,
			maxmin : true, // 开启最大化最小化按钮
			area : [ '893px', '600px' ],
			maxmin : true,
			content : '/plan/tasksPage',
			success : function(layero, index) {
				var iframeWin = window[layero.find('iframe')[0]['name']];
				var flag = iframeWin.setTable(tempTask);
			}
		});
	}
}

function exportExcel() {
	window.open("/problems/exportExcel");
}

function servicesListExportExcel() {
	layer.open({
		type : 2,
		title : "局端标准服务清册",
		shadeClose : true,
		shade : false,
		maxmin : true, // 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : '/servicesList/initServicesList'
	});
}

function openVersionPlanRisk(type) {
	var title;
	if (type == "noVersionPlan") {
		title = "无版本计划任务";
	} else if (type == "delayVersionPlan") {
		title = "延期出厂任务";
	}
	layer.open({
		type : 2,
		title : title,
		shadeClose : true,
		shade : false,
		maxmin : true, // 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : '/versionPlan/getRiskList?type=' + type
	});
}
function openVersionPlan() {
	var num = $("#versionPlanPage").val();

	layer.open({
		type : 2,
		title : "版本计划信息",
		shadeClose : true,
		shade : false,
		maxmin : true,
		// 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : '/versionPlan/getList?version=' + num
	});
}
function servicesMain() {
	layer.open({
		type : 2,
		title : "服务清单列表",
		shadeClose : true,
		shade : false,
		maxmin : true,
		// 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : '/servicesList/scsMainList'
	});
}